package com.itboye.jinpuyiyuan.activity.home.hospitalserver;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.itboye.jinpuyiyuan.R;
import com.itboye.jinpuyiyuan.adapter.DailyListDetailAdapter;
import com.itboye.jinpuyiyuan.base.BaseActivity;
import com.itboye.jinpuyiyuan.bean.DailyInfoBean;
import com.itboye.jinpuyiyuan.presenter.BranchAddressPresenter;
import com.itboye.jinpuyiyuan.utils.sputil.Const;
import com.itboye.jinpuyiyuan.utils.sputil.SPUtils;
import com.itboye.jinpuyiyuan.utils.volley.ResultEntity;
import com.itboye.jinpuyiyuan.widget.MyListView;
import com.itboye.jinpuyiyuan.widget.loadingutil.MAlert;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

/**
 * Created by Administrator on 2018/10/19 0019.
 */

public class DailyListDetailActivity extends BaseActivity implements Observer {

    //title
    private ImageView back;
    private TextView tvTitle;

    private TextView personNameTv;
    private TextView dateTv;
    private TextView moneyTv;
    private MyListView billList;
    private RelativeLayout topRl;

    private String uid;
    private String date;

    private BranchAddressPresenter presenter;
    private DailyListDetailAdapter adapter;
    private List<DailyInfoBean.Fee.FeeDetail> list;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.activity_dailylistdetail);
        tvTitle.setText("日清单明细");
        moneyTv.setText(getIntent().getStringExtra("money"));
        date=getIntent().getStringExtra("date");
        uid= SPUtils.get(this,null, Const.UID,"")+"";

        list=new ArrayList<>();

        presenter=new BranchAddressPresenter(this);
        presenter.dailyInfo(uid,date);


        adapter=new DailyListDetailAdapter(this,list);
        billList.setAdapter(adapter);

        topRl.setFocusable(true);
        topRl.setFocusableInTouchMode(true);
        topRl.requestFocus();
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()){

            case R.id.back:
                this.finish();
                break;


        }
    }

    @Override
    public void update(Observable o, Object arg) {

        ResultEntity resultEntity = handlerError(arg);

        if (resultEntity.getEventType()==BranchAddressPresenter.By_Hospitalization_dailyDetail_success){

            DailyInfoBean bean= (DailyInfoBean) resultEntity.getData();
            list=bean.getFee().getFee_detail();

            personNameTv.setText("病人姓名:  "+bean.getName());
            dateTv.setText("费用日期:  "+bean.getDate());
            adapter.addData(bean.getFee().getFee_detail());


        }else if (resultEntity.getEventType()==BranchAddressPresenter.By_Hospitalization_dailyDetail_fail){

            MAlert.alert(resultEntity.getMsg());
        }
    }
}
